using System;
using System.Data;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.ComponentModel;
using Fieldbook.Business;
using Fieldbook.Entities;
using System.Collections.Generic;

namespace Fieldbook.SAL
{
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    [WebService(Namespace = "http://fieldbook.sase.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    public class FieldbookService : System.Web.Services.WebService
    {
        public AutenhicationHeader Authentication;

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }

        private bool LogIn(AutenhicationHeader Authentication)
        {
            bool res = AppUserController.CheckLoginUser(Authentication.userName, Authentication.passWord);
            return res;
        }

        [WebMethod]
        [SoapHeader("Authentication", Direction = SoapHeaderDirection.InOut)]
        public Appuser GetLoggedUser()
        {
            Appuser res = null;
            if (LogIn(Authentication))
            {
                res = AppUserController.LoginUser(Authentication.userName, Authentication.passWord);
            }
            return res;
        }

        [WebMethod]
        [SoapHeader("Authentication", Direction = SoapHeaderDirection.InOut)]
        public List<Field> LoadHouseHoldFields(long userID)
        {
            List<Field> res = null;
            if (LogIn(Authentication))
            {
                res = FieldController.LoadHouseHoldFields(userID);
            }
            return res;
        }
    }

    public class AutenhicationHeader : SoapHeader
    {
        public string userName;
        public string passWord;
    }
}
